package donajurema;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import donajurema.model.Product;
import donajurema.model.ProductList;
import donajurema.model.Units;

import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.graphics.Point;


/**
 * Dona Jurema - easy shopping
 * A simple program that allows an user to maintain a product database and a shopping cart 
 * @author      Felipe Cavalcanti
 * @version     1.1
 * @since       1.6
 */
public class Form1
{
	protected Shell	shlDonaJurema;
	ProductList productDatabase = new ProductList("Products.xml");
	ProductList shoppingList= new ProductList("ShoppingList.xml");
	ProductList historyList= new ProductList("History.xml");
	private Text newProductTextName;
	private ComboViewer comboViewerUnits; 
	Product newProduct = new Product();
	TableLabelProvider tableLabelProvider = new TableLabelProvider();
	private Table tableProductDatabase;
	TableViewer tableViewerProductDatabase;
	TableViewer tableViewer_ShoppingList;
	private Table table_ShoppingList;
	private Table table_History;
	String shop = "";
	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args)
	{
		Display display = Display.getDefault();
		
		Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
			public void run() {
				try
				{
					Form1 window = new Form1();
					window.open();
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Open the window.
	 */
	public void open()
	{
		Display display = Display.getDefault();
		

		createContents();
		shlDonaJurema.open();
		shlDonaJurema.layout();
		while (!shlDonaJurema.isDisposed())
		{
			if (!display.readAndDispatch())
			{
				display.sleep();
			}
		}
	}
	
	private void delDatabaseProduct()
	{
		if (!tableViewerProductDatabase.getSelection().isEmpty()) 
		{
			IStructuredSelection selection = (IStructuredSelection)tableViewerProductDatabase.getSelection();
			for (Object o : selection.toArray())
			{
				Product p = (Product)o;
				productDatabase.removeProduct(p);
			}
			tableViewerProductDatabase.refresh();
		}
	}
	
	private void delShoppingListProduct()
	{
		if (!tableViewer_ShoppingList.getSelection().isEmpty()) 
		{
			IStructuredSelection selection = (IStructuredSelection)tableViewer_ShoppingList.getSelection();
			for (Object o : selection.toArray())
			{
				Product p = (Product)o;
				shoppingList.removeProduct(p);
			}
			tableViewer_ShoppingList.refresh();
		}
	}

	private void setShopName()
	{
		InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
	            "Shop name", "Enter shop name.", 
	            this.shop, null);
        if (dlg.open() == Window.OK) 
        {
        	// User clicked OK; update the shop name
        	this.shop = dlg.getValue();
        }
	}

	private void buyProduct()
	{
		if (shop == "") { setShopName();}

		if (!tableViewer_ShoppingList.getSelection().isEmpty()) 
		{
			IStructuredSelection selection = (IStructuredSelection)tableViewer_ShoppingList.getSelection();
			for (Object o : selection.toArray())
			{
				Product p = (Product)o;
				shoppingList.removeProduct(p);
				p.setShop(shop);
				p.refreshDate();
				historyList.addProduct(p);
			}
			tableViewer_ShoppingList.refresh();
		}
	}
	
	private void buyAllProducts()
	{
		if (shop == "") { setShopName();}

		for (Product p : shoppingList.getProducts())
		{
			shoppingList.removeProduct(p);
			p.setShop(shop);
			p.refreshDate();
			historyList.addProduct(p);
		}
		tableViewer_ShoppingList.refresh();
	}
	
	private void addDatabaseProduct()
	{
		Product copy = new Product(newProduct);
		productDatabase.addProduct(copy);
		tableViewerProductDatabase.refresh();
		newProductTextName.setText("");
		newProductTextName.setFocus();
	}
	
	private void addToShoppingList()
	{
		if (!tableViewerProductDatabase.getSelection().isEmpty()) 
		{
			IStructuredSelection selection = (IStructuredSelection)tableViewerProductDatabase.getSelection();
			for (Object o : selection.toArray())
			{
				Product p = (Product)o;
				readQuantity(p);
				if (p.getQuantity() != -1)	{ shoppingList.addProduct(p); }
			}
			tableViewerProductDatabase.refresh();
			tableViewer_ShoppingList.refresh();
		}
	}

	private void readQuantity(Product p)
	{
		InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
	            "Quantity", "Enter quantity in " + p.getUnit().toString()+ " for " + p.getName(), 
	            "0", new LengthValidator());
	        if (dlg.open() == Window.OK) 
	        {
	        	// User clicked OK; update the label with the input
	        	String quantityString =  dlg.getValue();
	        	Integer quantity = 0;
	        	try
				{
	        		 quantity = Integer.parseInt(quantityString);	
				}
				catch (NumberFormatException e) 
				{
					e.printStackTrace();
				}
	        	p.setQuantity(quantity);
	        }
	        else
	        {
	        	p.setQuantity(-1);
	        }
	}
	
	class LengthValidator implements IInputValidator 
	{
		  public String isValid(String newText) 
		  {
		    
			try
			{
				  Integer.parseInt(newText);	
			}
			catch (NumberFormatException e) 
			{
				return "Numbers only!";
			}
		    // Input must be OK
		    return null;
		  }
	}
	
	private void addOnKey(KeyEvent e)
	{
		switch (e.character) 
		{
	        case SWT.CR:
	        	addDatabaseProduct();
	        	break;
	        case SWT.ESC:
	        	newProductTextName.setText("");
	        	break;
	    }
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents()
	{
		
		shlDonaJurema = new Shell();
		shlDonaJurema.setImage(SWTResourceManager.getImage(Form1.class, "/resources/visa.png"));
		shlDonaJurema.setMinimumSize(new Point(400, 300));
		shlDonaJurema.setSize(513, 535);
		shlDonaJurema.setText("Dona Jurema vai as Compras");
		shlDonaJurema.setLayout(new FillLayout(SWT.VERTICAL));
		
		Menu menu = new Menu(shlDonaJurema, SWT.BAR);
		shlDonaJurema.setMenuBar(menu);
		
		MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
		mntmFile.setText("File");
		
		Menu menu_1 = new Menu(mntmFile);
		mntmFile.setMenu(menu_1);
		
		MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
		mntmExit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.exit(0);
			}
		});
		mntmExit.setText("Exit");
		
		MenuItem mntmShop = new MenuItem(menu, SWT.CASCADE);
		mntmShop.setText("Shop");
		
		Menu menu_2 = new Menu(mntmShop);
		mntmShop.setMenu(menu_2);
		
		MenuItem mntmShopName = new MenuItem(menu_2, SWT.NONE);
		mntmShopName.setText("Set Shop Name");
		
		MenuItem mntmBuyAll = new MenuItem(menu_2, SWT.NONE);
		mntmBuyAll.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) 
			{
				buyAllProducts();
			}
		});
		mntmBuyAll.setText("Buy All in List");
		
		TabFolder tabFolder = new TabFolder(shlDonaJurema, SWT.NONE);
		tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
		
		TabItem tabItemProducts = new TabItem(tabFolder, SWT.NONE);
		tabItemProducts.setText("Products");
		
		
		// Products DATABASE
		Composite composite = new Composite(tabFolder, SWT.NONE);
		tabItemProducts.setControl(composite);
		composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
		GridLayout gl_composite = new GridLayout();
		gl_composite.verticalSpacing = 0;
		composite.setLayout(gl_composite);
		
		// Composite Products Database Table
		Composite composite_table = new Composite(composite, SWT.NONE);
		GridData gd_composite_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
		gd_composite_table.heightHint = 317;
		composite_table.setLayoutData(gd_composite_table);
		TableColumnLayout layout = new TableColumnLayout();
		composite_table.setLayout(layout);
		
			tableViewerProductDatabase = new TableViewer(composite_table, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
			tableProductDatabase = tableViewerProductDatabase.getTable();
			tableProductDatabase.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDoubleClick(MouseEvent e) 
				{
		        	addToShoppingList();
				}
			});
			tableProductDatabase.setSize(410, 361);
			tableProductDatabase.addKeyListener(new KeyAdapter() {
				@Override
				public void keyPressed(KeyEvent e) 
				{
					switch (e.character) 
					{
				        case SWT.CR:
				        	addToShoppingList();
				        	break;
				        case SWT.DEL:
				        	delDatabaseProduct();
				        	break;
				        case SWT.ESC:
				        	newProductTextName.setText("");
				        	newProductTextName.setFocus();
				        	break;
				    }
					
				}
			});
			tableProductDatabase.setLinesVisible(true);
			tableProductDatabase.setHeaderVisible(true);
			
			TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewerProductDatabase, SWT.NONE);
			TableColumn tblclmnName = tableViewerColumn.getColumn();
			tblclmnName.setResizable(false);
			tblclmnName.setMoveable(true);
			tblclmnName.setWidth(300);
			tblclmnName.setText("Name");
			
			TableViewerColumn tableViewerColumn_10 = new TableViewerColumn(tableViewerProductDatabase, SWT.NONE);
			TableColumn tblclmnQuantity_1 = tableViewerColumn_10.getColumn();
			layout.setColumnData(tblclmnQuantity_1, new ColumnPixelData(1, true, true));
			tblclmnQuantity_1.setText("Quantity");
			
			TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewerProductDatabase, SWT.NONE);
			TableColumn tblclmnUnits = tableViewerColumn_1.getColumn();
			tblclmnUnits.setResizable(false);
			tblclmnUnits.setWidth(70);
			tblclmnUnits.setText("Unit");
			
			// Table column percentage.
			layout.setColumnData( tblclmnName, new ColumnWeightData(10));
			layout.setColumnData( tblclmnQuantity_1, new ColumnPixelData(0));
			layout.setColumnData( tblclmnUnits, new ColumnPixelData(70));
			
						tableViewerProductDatabase.setContentProvider(ArrayContentProvider.getInstance());
						tableViewerProductDatabase.setLabelProvider(tableLabelProvider);
						tableViewerProductDatabase.setInput(productDatabase.getProducts());
						
						Menu menuProductsDatabase = new Menu(tableProductDatabase);
						tableProductDatabase.setMenu(menuProductsDatabase);
						
						MenuItem mntmAddToShopping = new MenuItem(menuProductsDatabase, SWT.NONE);
						mntmAddToShopping.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								addToShoppingList();
							}
						});
						mntmAddToShopping.setText("Add to Shopping list");
						
						MenuItem mntmDeleteProduct = new MenuItem(menuProductsDatabase, SWT.NONE);
						mntmDeleteProduct.setImage(SWTResourceManager.getImage(Form1.class, "/resources/del.gif"));
						mntmDeleteProduct.addSelectionListener(new SelectionAdapter() {
							@Override
							public void widgetSelected(SelectionEvent e) {
								delDatabaseProduct();
							}
						});
						mntmDeleteProduct.setText("Delete");
						
						// Group
						Group grpAddNewProduct = new Group(composite, SWT.SHADOW_ETCHED_IN);
						grpAddNewProduct.setLayout(new GridLayout(3, false));
						GridData gd_grpAddNewProduct = new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1);
						gd_grpAddNewProduct.minimumWidth = 200;
						gd_grpAddNewProduct.widthHint = 411;
						grpAddNewProduct.setLayoutData(gd_grpAddNewProduct);
						grpAddNewProduct.setText("Add new product");
						
						Label lblNewLabel = new Label(grpAddNewProduct, SWT.NONE);
						lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
						lblNewLabel.setText("Name");
						
						Label lblUnit = new Label(grpAddNewProduct, SWT.NONE);
						lblUnit.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
						lblUnit.setText("Unit");
						new Label(grpAddNewProduct, SWT.NONE);
						
						newProductTextName = new Text(grpAddNewProduct, SWT.BORDER);
						newProductTextName.addKeyListener(new KeyAdapter() {
							@Override
							public void keyPressed(KeyEvent e) 
							{
								addOnKey(e);
							}
						});
						
									GridData gd_textName = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
									gd_textName.widthHint = 247;
									newProductTextName.setLayoutData(gd_textName);
									
									comboViewerUnits = new ComboViewer(grpAddNewProduct, SWT.READ_ONLY);
									Combo comboUnits = comboViewerUnits.getCombo();
									comboUnits.addKeyListener(new KeyAdapter() {
										@Override
										public void keyPressed(KeyEvent e) {
											addOnKey(e);
										}
									});
									GridData gd_comboUnits = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
									gd_comboUnits.widthHint = 40;
									comboUnits.setLayoutData(gd_comboUnits);
									comboViewerUnits.setContentProvider(ArrayContentProvider.getInstance());
									comboViewerUnits.setInput(Units.values());
									
									Button btnNewButton = new Button(grpAddNewProduct, SWT.NONE);
									btnNewButton.addMouseListener(new MouseAdapter() {
										@Override
										public void mouseDown(MouseEvent e) {
											addDatabaseProduct();
										}
									});
									btnNewButton.addKeyListener(new KeyAdapter() {
										@Override
										public void keyPressed(KeyEvent e) 
										{
											addOnKey(e);
										}
									});
									GridData gd_btnNewButton = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
									gd_btnNewButton.widthHint = 70;
									btnNewButton.setLayoutData(gd_btnNewButton);
									btnNewButton.setText("Add");
									new Label(composite, SWT.NONE);
									
		// Table Shopping List
		TabItem tbtmShoppingList = new TabItem(tabFolder, 0);
		tbtmShoppingList.setText("Shopping List");
		
		Composite composite_ShoppingList = new Composite(tabFolder, SWT.NONE);
		tbtmShoppingList.setControl(composite_ShoppingList);
		TableColumnLayout tcl_composite_ShoppingList = new TableColumnLayout();
		composite_ShoppingList.setLayout(tcl_composite_ShoppingList);
		
		tableViewer_ShoppingList = new TableViewer(composite_ShoppingList, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
		table_ShoppingList = tableViewer_ShoppingList.getTable();
		table_ShoppingList.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDoubleClick(MouseEvent e) 
			{
				buyProduct();
			}
		});
		table_ShoppingList.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) 
			{
				switch (e.character) 
				{
			        case SWT.DEL:
			        	delShoppingListProduct();
			        	break;
			        case SWT.CR:
			        	buyProduct();
			        	break;
				}
			}
		});
		table_ShoppingList.setHeaderVisible(true);
		table_ShoppingList.setLinesVisible(true);
		
		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer_ShoppingList, SWT.NONE);
		TableColumn tblclmnName_1 = tableViewerColumn_2.getColumn();
		tcl_composite_ShoppingList.setColumnData(tblclmnName_1, new ColumnPixelData(150, true, true));
		tblclmnName_1.setText("Name");
		
		TableViewerColumn tableViewerColumn_3 = new TableViewerColumn(tableViewer_ShoppingList, SWT.NONE);
		TableColumn tblclmnQuantity = tableViewerColumn_3.getColumn();
		tcl_composite_ShoppingList.setColumnData(tblclmnQuantity, new ColumnPixelData(150, true, true));
		tblclmnQuantity.setText("Quantity");
		
		TableViewerColumn tableViewerColumn_4 = new TableViewerColumn(tableViewer_ShoppingList, SWT.NONE);
		TableColumn tblclmnUnit = tableViewerColumn_4.getColumn();
		tcl_composite_ShoppingList.setColumnData(tblclmnUnit, new ColumnPixelData(150, true, true));
		tblclmnUnit.setText("Unit");
		
				tableViewer_ShoppingList.setContentProvider(ArrayContentProvider.getInstance());
				tableViewer_ShoppingList.setLabelProvider(tableLabelProvider);
				tableViewer_ShoppingList.setInput(shoppingList.getProducts());
				
				// Table Shopping List column percentage.
				tcl_composite_ShoppingList.setColumnData( tblclmnName_1, new ColumnWeightData(10));
				tcl_composite_ShoppingList.setColumnData( tblclmnQuantity, new ColumnPixelData(70));
				tcl_composite_ShoppingList.setColumnData( tblclmnUnit, new ColumnPixelData(70));
				
				Menu menuShoppingList = new Menu(table_ShoppingList);
				table_ShoppingList.setMenu(menuShoppingList);
				
				MenuItem mntmBuy = new MenuItem(menuShoppingList, SWT.NONE);
				mntmBuy.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) 
					{
						buyProduct();
					}
				});
				mntmBuy.setText("Buy");
				
				MenuItem mntmRemove = new MenuItem(menuShoppingList, SWT.NONE);
				mntmRemove.addSelectionListener(new SelectionAdapter() {
					@Override
					public void widgetSelected(SelectionEvent e) 
					{
						delShoppingListProduct();
					}
				});
				mntmRemove.setImage(SWTResourceManager.getImage(Form1.class, "/resources/del.gif"));
				mntmRemove.setText("Remove");
				
				// Table History
				TabItem tbtmHistory = new TabItem(tabFolder, SWT.NONE);
				tbtmHistory.setText("History");
				
				Composite composite_History = new Composite(tabFolder, SWT.NONE);
				tbtmHistory.setControl(composite_History);
				TableColumnLayout tcl_composite_History = new TableColumnLayout();
				composite_History.setLayout(tcl_composite_History);
				
				TableViewer tableViewer_History = new TableViewer(composite_History, SWT.BORDER | SWT.FULL_SELECTION);
				table_History = tableViewer_History.getTable();
				table_History.setHeaderVisible(true);
				table_History.setLinesVisible(true);
				
				TableViewerColumn tableViewerColumn_5 = new TableViewerColumn(tableViewer_History, SWT.NONE);
				TableColumn tblclmnName_History = tableViewerColumn_5.getColumn();
				tcl_composite_History.setColumnData(tblclmnName_History, new ColumnPixelData(150, true, true));
				tblclmnName_History.setText("Name");
				
				TableViewerColumn tableViewerColumn_6 = new TableViewerColumn(tableViewer_History, SWT.NONE);
				TableColumn tblclmnQuantity_History = tableViewerColumn_6.getColumn();
				tcl_composite_History.setColumnData(tblclmnQuantity_History, new ColumnPixelData(150, true, true));
				tblclmnQuantity_History.setText("Quantity");
				
				TableViewerColumn tableViewerColumn_7 = new TableViewerColumn(tableViewer_History, SWT.NONE);
				TableColumn tblclmnUnit_History = tableViewerColumn_7.getColumn();
				tcl_composite_History.setColumnData(tblclmnUnit_History, new ColumnPixelData(150, true, true));
				tblclmnUnit_History.setText("Unit");
				
				TableViewerColumn tableViewerColumn_8 = new TableViewerColumn(tableViewer_History, SWT.NONE);
				TableColumn tblclmnShop = tableViewerColumn_8.getColumn();
				tcl_composite_History.setColumnData(tblclmnShop, new ColumnPixelData(150, true, true));
				tblclmnShop.setText("Shop");
				
				TableViewerColumn tableViewerColumn_9 = new TableViewerColumn(tableViewer_History, SWT.NONE);
				TableColumn tblclmnDate = tableViewerColumn_9.getColumn();
				tcl_composite_History.setColumnData(tblclmnDate, new ColumnPixelData(150, true, true));
				tblclmnDate.setText("Date");
				
				tableViewer_History.setContentProvider(ArrayContentProvider.getInstance());
				tableViewer_History.setLabelProvider(tableLabelProvider);
				tableViewer_History.setInput(historyList.getProducts());
				
				tcl_composite_History.setColumnData( tblclmnName_History, new ColumnWeightData(70));
				tcl_composite_History.setColumnData( tblclmnQuantity_History, new ColumnPixelData(60));
				tcl_composite_History.setColumnData( tblclmnUnit_History, new ColumnPixelData(55));
				tcl_composite_History.setColumnData( tblclmnShop, new ColumnWeightData(30));
				tcl_composite_History.setColumnData( tblclmnDate, new ColumnPixelData(80));
	
	
		initDataBindings();
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue textNameObserveTextObserveWidget = SWTObservables.observeText(newProductTextName, SWT.Modify);
		IObservableValue newProductNameObserveValue = BeansObservables.observeValue(newProduct, "name");
		bindingContext.bindValue(textNameObserveTextObserveWidget, newProductNameObserveValue, null, null);
		//
		IObservableValue comboViewerObserveSingleSelection = ViewersObservables.observeSingleSelection(comboViewerUnits);
		IObservableValue newProductUnitObserveValue = BeansObservables.observeValue(newProduct, "unit");
		bindingContext.bindValue(comboViewerObserveSingleSelection, newProductUnitObserveValue, null, null);
		//
		return bindingContext;
	}
}
